/**
 * @Copyright (c) 2005, 上海鸿域信息科技有限公司 
 * @All rights reserved.
 *
 * DAjax cache 系统,雏形
 *
 * @file_name   Cache.js
 * @version     1.0
 * @author      黄新泽
 * @date        2005-10-08 16:09:40
 */

var	Cache = Class.create({
	cData : {},

	initialize : function(prefix, life_time) 
	{
		if (!prefix)
		{
			prefix = 'd';
		}

		this.key    = false;

		this.prefix   = prefix;

		if (!life_time)
		{
			this.lifeTime = 0   ;
		}
		else
		{
			this.lifeTime = life_time;
		}
		

		this.cData[this.prefix] = {};
	},


	getCache : function(key)
	{
		if (!Object.isUndefined(this.cData[this.prefix][key]) && this.cData[this.prefix][key])
		{
			//如果lifetime 为0, 则永远不失效
			if (this.lifeTime && ((intVal(new Date().getTime()/1000)-this.cData[this.prefix][key]['time'])) > this.lifeTime)
			{
				this.delCache(key);
				return false;
			}

			return this.cData[this.prefix][key]['value'];
		}
		else
		{
			return false;
		}
		
	},

	updateCache : function(key, value)
	{
		this.cData[this.prefix][key] = {};
		this.cData[this.prefix][key]['value'] = value;
		this.cData[this.prefix][key]['time'] = intVal(new Date().getTime()/1000);
	},

	delCache : function(key)
	{
		this.cData[this.prefix][key] = null;
	},

	delCacheAll : function()
	{
		this.cData[this.prefix] = {};
	}
});